package nodes;

import java.util.LinkedList;
import java.util.List;

import compiler.Compiler;
import compiler.SymbolTable;

import descriptors.AbstractDescr;
import descriptors.VarDescr;

public class FPSectionNode extends AbstractNode {

	private boolean isVar;
	private ListNode<IdentNode> identList;
	private AbstractNode type;
	
	
	public FPSectionNode(boolean isVar,ListNode<IdentNode> identList,AbstractNode type,int line, int column){
		super(line,column);
		this.identList=identList;
		this.type=type;
		this.isVar=isVar;
	}
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public AbstractDescr compile(
			SymbolTable symbolTable, Compiler compiler) {
		return null;
	}

	public List<AbstractDescr> compileParams(SymbolTable symbolTable,Compiler compiler){
		List<AbstractDescr> list = new LinkedList<AbstractDescr>();
		AbstractDescr typeD = type.compile(symbolTable,compiler);
		for (IdentNode elem: identList) {
			compiler.setAddress(compiler.address() - typeD.getSize());
			AbstractDescr varD = new VarDescr(compiler.level(), compiler.address(), isVar, typeD);
			list.add(varD);
			symbolTable.set(elem.ident(), varD);
		}
		return list;
	}
	
	@Override
	public void print() {
		String var=isVar ? "VAR" : "";
		trace("FPSectionNode "+var);
		identList.print();
		type.print();
		unindent();
		
	}

}
